/*
 * Roberts.cpp
 *
 *  Created on: Dec 7, 2009
 *      Author: tptfc
 */

#include "Roberts.h"
#include <math.h>

Roberts::Roberts(int limiar) {
	setLimiar(limiar);
}

Roberts::~Roberts() {
}

void Roberts::applyFilterInVector(int width, int height, int **vectors, int **newVectors) {
	#pragma omp parallel for default(shared)
	for (int i = 0; i < height; i++) {
		#pragma omp parallel for default(shared)
		for (int j = 0; j < width; j++) {
			int centerRight = getCenterRightValue(i, j, width, height, vectors);
			int dowRight = getDownRightValue(i, j, width, height, vectors);
			int dowCenter = getDownCenterValue(i, j, width, height, vectors);

			int tmp = sqrt((pow((dowRight - vectors[i][j]),2) + pow((dowCenter - centerRight),2)));

			if (getLimiar() > 255) {
				newVectors[i][j] = tmp;
			} else {
				newVectors[i][j] = (tmp > limiar) ? 255 : 0;
			}
		}
	}
}

void Roberts::setLimiar(int limiar) {
	this->limiar = limiar;
}

int Roberts::getLimiar() {
	return limiar;
}
